var isShortsDeleted = false;

function removeShorts()
{
    const shortsBlocks = [
        ...document.querySelectorAll(
            "ytd-rich-section-renderer.style-scope.ytd-rich-grid-renderer"
        ),
        ...document.querySelectorAll(
            "ytd-reel-shelf-renderer.style-scope.ytd-item-section-renderer"
        )
    ];
    shortsBlocks.forEach(shortsBlock => {
        shortsBlock.remove();
    });
}

function removeShortsFromMenu()
{
    if (isShortsDeleted) return;
    isShortsDeleted = true;
    let shortsButton = document.querySelector(
        "ytd-guide-entry-renderer.style-scope.ytd-guide-section-renderer"
        + " a[title=\"Shorts\"]"
    );
    setTimeout(() => shortsButton.remove(), 100);
}

function removeShortsFromMiniMenu()
{
    document.querySelector(
        "ytd-mini-guide-entry-renderer"
        + ".style-scope.ytd-mini-guide-renderer[aria-label=\"Shorts\"]"
    ).remove();
}

setInterval(removeShorts, 1000);
setTimeout(removeShortsFromMiniMenu, 1000)
setTimeout(() => {
    document.querySelector(
        "yt-icon-button#guide-button.style-scope.ytd-masthead"
        + " button.style-scope.yt-icon-button"
    ).addEventListener("click", removeShortsFromMenu);
}, 1000)

const shortsExpr = /https:\/\/www\.youtube\.com\/shorts\/[a-zA-Z0-9_-]+/;
let currentPage = window.location.href;
setInterval(() => {
    if (currentPage == window.location.href)
    {
        return;
    }
    console.log(currentPage, window.location.href);
    currentPage = window.location.href;
    if (window.location.href.match(shortsExpr))
    {
        console.log("match");
        window.location.replace("https://www.youtube.com");
    }
}, 500);
